home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BKISSSRC.ZIP / TUNNEL / HEART.BAS < prev    next >
Encoding:
BASIC Source File  |  1994-02-10  |  2.6 KB  |  92 lines

  1. DEFSNG A-Z
  2.  
  3. CONST Range = 256
  4. CONST DuplicateFactor = 50
  5.  
  6. RANDOMIZE TIMER
  7.  
  8. TYPE PointType
  9. X AS SINGLE
  10. Y AS SINGLE
  11. END TYPE
  12.  
  13. 'count the number of points in the file
  14. OPEN "HEART.ASC" FOR INPUT AS #1
  15. NumPoints = 0
  16. DO
  17.     LINE INPUT #1, A$
  18.     X = VAL(MID$(A$, INSTR(A$, "X:") + 3))
  19.     Y = VAL(MID$(A$, INSTR(A$, "Y:") + 3))
  20.     Z = VAL(MID$(A$, INSTR(A$, "Z:") + 3))
  21.     NumPoints = NumPoints + 1
  22. LOOP UNTIL EOF(1)
  23.  
  24. 'allocate memory and load in the points
  25. SEEK #1, 1
  26. DIM Points(1 TO NumPoints) AS PointType
  27. FOR Count = 1 TO NumPoints
  28.     LINE INPUT #1, A$
  29.     Points(Count).X = VAL(MID$(A$, INSTR(A$, "X:") + 3))
  30.     Points(Count).Y = VAL(MID$(A$, INSTR(A$, "Z:") + 3))
  31. NEXT Count
  32. CLOSE #1
  33.  
  34. 'determine the range of the points in the figure
  35. MinX = 32767: MaxX = -32767: MinY = 32767: MaxY = -32767
  36. FOR Count = 1 TO NumPoints
  37.     IF Points(Count).X > MaxX THEN MaxX = Points(Count).X
  38.     IF Points(Count).X < MinX THEN MinX = Points(Count).X
  39.     IF Points(Count).Y > MaxY THEN MaxY = Points(Count).Y
  40.     IF Points(Count).Y < MinY THEN MinY = Points(Count).Y
  41. NEXT Count
  42. NumX = MaxX - MinX: NumY = MaxY - MinY
  43.  
  44. 'scale all of the points so that they're in our desired range
  45. SCREEN 12: CLS : WINDOW SCREEN (-Range, -Range)-(Range, Range)
  46. FOR Count = 1 TO NumPoints
  47.     'get the X and Y coordinates in the range of 0.0 to 1.0
  48.     Points(Count).X = (Points(Count).X - MinX) / NumX
  49.     Points(Count).Y = (Points(Count).Y - MinY) / NumY
  50.     IF (Points(Count).X > 1 OR Points(Count).X < 0) THEN STOP
  51.     IF (Points(Count).Y > 1 OR Points(Count).Y < 0) THEN STOP
  52.  
  53.     'get the X and Y coordinates in the range of -Range to +Range
  54.     Points(Count).X = (Points(Count).X - .5) * 2 * Range
  55.     Points(Count).Y = -(Points(Count).Y - .5) * 2 * Range
  56.  
  57.     PSET (Points(Count).X, Points(Count).Y), 15
  58. NEXT Count
  59.  
  60. 'randomly shuffle them
  61. PRINT "Shuffling..."
  62. FOR Count = 1 TO NumPoints ^ 2
  63.     SWAP Points(INT(RND * NumPoints + 1)), Points(INT(RND * NumPoints + 1))
  64. NEXT Count
  65.  
  66. 'write out our computed points
  67. OPEN "HEART.INC" FOR OUTPUT AS #1
  68. PRINT #1, "STRUC Point_Type"
  69. PRINT #1, "X DW ?"
  70. PRINT #1, "Y DW ?"
  71. PRINT #1, "ENDS Point_Type"
  72. PRINT #1,
  73. PRINT #1, "NumDefaultPoints ="; NumPoints
  74. PRINT #1, "LABEL DefaultPoints Point_Type"
  75. Count = 0
  76. FOR X = 1 TO NumPoints
  77.     IF Count = 0 THEN
  78.         PRINT #1, "Point_Type ";
  79.     ELSE
  80.         PRINT #1, ",";
  81.     END IF
  82.  
  83.     PRINT #1, "<"; LTRIM$(RTRIM$(STR$(CINT(Points(X).X)))); ","; LTRIM$(RTRIM$(STR$(CINT(Points(X).Y)))); ">";
  84.     Count = Count + 1
  85.     IF Count > 4 THEN
  86.         PRINT #1,
  87.         Count = 0
  88.     END IF
  89. NEXT X
  90. CLOSE #1
  91.  
  92.